package shopline

import "time"

type MerchantAppsOperateType string

const MerchantAppsOperateInstalled MerchantAppsOperateType = "INSTALL"
const MerchantAppsOperateUninstalled MerchantAppsOperateType = "UNINSTALL"

// appConfig config.toml配置文件里面的参数
type appConfig struct {
	AppName        string `json:"app_name,omitempty"`
	AppDescription string `json:"app_description,omitempty"`
	AppUrl         string `json:"app_url,omitempty"`
	AppKey         string `json:"app_key,omitempty" `
	AppSecret      string `json:"app_secret,omitempty"`
}

/*
authorizeRequest
https://developer.myshopline.com/docs/introduce/NOAkhsPT
1. 点击“去使用”，请求应用
appkey		String	query	Y	应用唯一标识
timestamp	String	query	Y	时间戳
sign		String	query	Y	安全签名，算法：hmacsha256，签名方式见本页签名机制【hMacSha256】
handle		String	query	Y	店铺唯一标识，店铺域名前缀，如：zhangsan.myshopline.com的handle为：zhangsan
lang		String	query	N	店铺当前语种，内嵌应用会返回该字段
*/
type authorizeRequest struct {
	// AppName 是 uri path 参数，计算签名的时候需要排除
	AppName   string `p:"shopline_app_name"`
	AppKey    string
	Handle    string
	Lang      string
	Timestamp string
	Sign      string
}

/*
callbackRequest
3. 确认授权，收到回调
https://xxx.com/callback?appkey=326383c947bca5e042807537743f0114a84fb709&code=sgef5900943de8bff669569b92d8559aca31fc6681&handle=goodgoods&lang=zh-hans-cn&timestamp=1646915628733&sign=63d5aafdf652a00cc45258bbdb9a448b021088175ce1036c6b82cabd8b9980b1
*/
type callbackRequest struct {
	AppName     string `p:"shopline_app_name"`
	AppKey      string
	Handle      string
	Code        string
	Timestamp   string
	Sign        string
	Lang        string
	CustomField string
}

type createTokenResponse struct {
	Code    int         `json:"code"`
	Message interface{} `json:"message"`
	Data    struct {
		AccessToken       string      `json:"accessToken"`
		ExpireTime        time.Time   `json:"expireTime"`
		RefreshToken      string      `json:"refreshToken"`
		RefreshExpireTime time.Time   `json:"refreshExpireTime"`
		Scope             interface{} `json:"scope"`
	} `json:"data"`
}

type refreshTokenRequest struct {
	AppName   string `json:"app_name,omitempty"`
	Handle    string `json:"handle,omitempty"`
	Timestamp string `json:"timestamp,omitempty"`
	Signature string `json:"signature,omitempty"`
}

// 前端刷新token，返回用
type refreshTokenResponse struct {
	AccessToken string `json:"access_token,omitempty"`
	Expiration  int64  `json:"expiration,omitempty"`
}

// queryMerchantShopInfoResponse 查询店铺信息返回的数据
// https://developer.myshopline.com/docs/api/v9nbZbRk
type queryMerchantShopInfoResponse struct {
	Data struct {
		LocationCountryCode string `json:"location_country_code"`
		CustomerEmail       string `json:"customer_email"`
		Name                string `json:"name"`
		Currency            string `json:"currency"`
		ID                  uint   `json:"id"`
		Email               string `json:"email"`
	} `json:"data"`
}

// MerchantInfo 商家信息
type MerchantInfo struct {
	Email       string `json:"email,omitempty"`
	StoreId     uint   `json:"store_id,omitempty"`
	StoreName   string `json:"store_name,omitempty"`
	StoreTitle  string `json:"store_title,omitempty"`
	CountryCode string `json:"country_code,omitempty"`
}

// MerchantAppsOperateInfo 商户应用启用卸载信息
/*
{
  "appkey": "fe5730faeaa6de132e9495bdecd8c474b93199f4",
  "country_code": "US",
  "created_at": "2022-06-30T17:20:38+08:00",
  "handle": "wangxu",
  "has_extension": false,
  "merchant_id": "2001203948",
  "name": "网旭测试",
  "operate": "INSTALL",
  "store_id": "1656323355306",
  "timestamp": 1656580838017,
  "zone": "Asia/Shanghai"
}
*/
type MerchantAppsOperateInfo struct {
	Operate   MerchantAppsOperateType `json:"operate,omitempty"`
	AppKey    string                  `json:"appkey,omitempty"`
	AppName   string                  `json:"app_name,omitempty"`
	StoreId   uint                    `json:"store_id,omitempty"`
	StoreName string                  `json:"handle,omitempty"`
}
